<?php
class CRedis extends CCache {
    public $servers;
    private $_cache;
    
    public function __construct()
    {
        parent::init();
        $this->_cache = new Redis();
        $this->_cache->connect(DXW_REDIS_ADDR,DXW_REDIS_PORT);
        $this->_cache->auth(DXW_REDIS_PWD);

    }
    public static function create(){
        return new self;
    }

    //设置数组中 单独元素  覆盖式
    public function setVal($name, $key, $value,$time=null){
    	if($time){
    		$this->setTime($name, $time);
    	}
    	$this->_cache->hSet($name, $key, $value);
    }
    
    //获取数组中单独元素  
    public function getVal($name,$key){
    	return $this->_cache->hGet($name,$key) ;
    }
    
    //设置元素过期时间时间
    public function setTime($key,$time){
    	$this->_cache->expire($key,$time);
    }
    
    //设置缓存数组
    public function setArr($name,$arr,$time=null){
    	if($time) $this->setTime($name, $time);
    	$this->_cache->hMset($name,$arr);
    }
    
    //获取缓存数组
    public function getArr($name){
    	return $this->_cache->hGetAll($name);
    }
    
    //判断数组元素是否存在
    public function h_exist($name,$key){
    	return $this->_cache->hExists($name,$key);
    }
    
    //判断元素是否存在
    public function exist($name){
    	return $this->_cache->exists($name);
    }
    
    //删除数组元素
    public function h_del($name,$key){
    	return $this->_cache->hdel($name,$key);
    }
    
    //删除元素
    public function del($key){    	
    	return $this->_cache->del($key);
    }
    
    //获取数组count
    public function count($key){
    	return $this->_cache->size($key);
    }
    
    //清除缓存
    public function flush(){
    	return $this->_cache->flushAll();
    }
    
    //单个缓存添加
    public function set_c($key,$value,$time=null){
    	if($time){
    		$this->setTime($key, $time);
    	}
    	$this->_cache->set($key,$value);
    }
    
    //单个缓存获取
    public function get_c($key){
    	return $this->_cache->get($key);
    }
    //左推 右出
    public function push($k,$v){
        $this->_cache->push($k,$v);
    }
    public function pull($k){
        return $this->_cache->pop($k);
    }

}